home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpu / m6502 / opsce02.h < prev    next >
Text File  |  2000-05-08  |  15KB  |  441 lines

  1. /*****************************************************************************
  2.  *
  3.  *     opsce02.h
  4.  *     Addressing mode and opcode macros for 65ce02 CPU
  5.  *
  6.  *     Copyright (c) 2000 Peter Trauner, all rights reserved.
  7.  *   documentation preliminary databook
  8.  *     documentation by michael steil mist@c64.org
  9.  *     available at ftp://ftp.funet.fi/pub/cbm/c65
  10.  *
  11.  *     - This source code is released as freeware for non-commercial purposes.
  12.  *     - You are free to use and redistribute this code in modified or
  13.  *       unmodified form, provided you list me in the credits.
  14.  *     - If you modify this source code, you must add a notice to each modified
  15.  *       source file that it has been changed.  If you're a nice person, you
  16.  *       will clearly mark each change too.  :)
  17.  *     - If you wish to use this for commercial purposes, please contact me at
  18.  *       pullmoll@t-online.de
  19.  *     - The author of this copywritten work reserves the right to change the
  20.  *       terms of its usage and license at any time, including retroactively
  21.  *     - This entire notice must remain in the source code.
  22.  *
  23.  *****************************************************************************/
  24.  
  25. #define m6502 m65ce02
  26. #define m6502_ICount m65ce02_ICount
  27.  
  28. /* stack disable extended (word) mode */
  29. #undef F_T
  30. #define F_E 0x20
  31.  
  32. /* some shortcuts for improved readability */
  33. #define Z    m65ce02.z
  34. #define B    m65ce02.zp.b.h
  35. #define SW m6502.sp.w.l
  36. #define SPL m6502.sp.b.l
  37. #define SPH m6502.sp.b.h
  38.  
  39. #define PEEK_OP() cpu_readop(PCW)
  40.  
  41. #define RDMEM_WORD(addr, pair)            \
  42.    pair.b.l=RDMEM( addr );                \
  43.    pair.b.h=RDMEM( (addr+1) & 0xffff )
  44.  
  45. #define WRMEM_WORD(addr,pair)            \
  46.    WRMEM(addr,pair.b.l);                \
  47.    WRMEM((addr+1)&0xffff,pair.b.h)
  48.  
  49. #define WB_EA_WORD    WRMEM_WORD(EAD, tmp)
  50.  
  51.  
  52. #define SET_NZ_WORD(n)                                            \
  53.     if( n.w.l == 0 )                                            \
  54.         P = (P & ~F_N) | F_Z;                                    \
  55.     else                                                        \
  56.         P = (P & ~(F_N | F_Z)) | ((n.b.h) & F_N)
  57.  
  58. /***************************************************************
  59.  *    EA = zero page indirect + Z (post indexed)
  60.  *    subtract 1 cycle if page boundary is crossed
  61.  ***************************************************************/
  62. #define EA_IDZ                                                    \
  63.     ZPL = RDOPARG();                                            \
  64.     EAL = RDMEM(ZPD);                                            \
  65.     ZPL++;                                                        \
  66.     EAH = RDMEM(ZPD);                                            \
  67.     if (EAL + Z > 0xff)                                         \
  68.         m6502_ICount--;                                         \
  69.     EAW += Z
  70.  
  71. /***************************************************************
  72.  *    EA = zero page indexed stack, indirect + Y (post indexed)
  73.  *    subtract 1 cycle if page boundary is crossed
  74.  ***************************************************************/
  75. /* i think its based on stack high byte instead of of bank register */
  76. #define EA_ZP_INSP_INY                                            \
  77. {                                                                \
  78.     PAIR pair={{0}};                                            \
  79.     pair.b.l = SPL+RDOPARG();                                    \
  80.     pair.b.h = SPH;                                             \
  81.     EAL = RDMEM(pair.d);                                        \
  82.     if( P & F_E )                                                \
  83.         pair.b.l++;                                             \
  84.     else                                                        \
  85.         pair.w.l++;                                             \
  86.     EAH = RDMEM(pair.d);                                        \
  87.     if( EAL + Y > 0xff )                                        \
  88.         m6502_ICount--;                                         \
  89.     EAW += Y;                                                    \
  90. }
  91.  
  92. #define RD_IMM_WORD tmp.b.l = RDOPARG(); tmp.b.h=RDOPARG()
  93. #define RD_IDZ    EA_IDZ; tmp = RDMEM(EAD)
  94. #define WR_IDZ    EA_IDZ; WRMEM(EAD, tmp)
  95.  
  96. #define RD_INSY EA_ZP_INSP_INY; tmp = RDMEM(EAD)
  97. #define WR_INSY EA_ZP_INSP_INY; WRMEM(EAD, tmp)
  98.  
  99. #define RD_ABS_WORD EA_ABS; RDMEM_WORD(EAD, tmp)
  100. #define WR_ABS_WORD EA_ABS; WRMEM_WORD(EAD, tmp)
  101.  
  102. #define RD_ZPG_WORD EA_ZPG; RDMEM_WORD(EAD, tmp)
  103. #define WR_ZPG_WORD EA_ZPG; WRMEM_WORD(EAD, tmp)
  104.  
  105. /***************************************************************
  106.  * push a register onto the stack
  107.  ***************************************************************/
  108. #undef PUSH
  109. #define PUSH(Rg) WRMEM(SPD, Rg); if (P&F_E) { S--; } else { SW--; }
  110.  
  111. /***************************************************************
  112.  * pull a register from the stack
  113.  ***************************************************************/
  114. #undef PULL
  115. #define PULL(Rg) if (P&F_E) { S++; } else { SW++; } Rg = RDMEM(SPD)
  116.  
  117. /* the order in which the args are pushed is correct! */
  118. #define PUSH_WORD(pair) PUSH(pair.b.l);PUSH(pair.b.h)
  119.  
  120. /***************************************************************
  121.  *    BRA  branch relative
  122.  *    extra cycle if page boundary is crossed
  123.  ***************************************************************/
  124. #define BRA_WORD(cond)                                            \
  125.     if (cond)                                                    \
  126.     {                                                            \
  127.         EAL = RDOPARG();                                        \
  128.         EAH = RDOPARG();                                        \
  129.         EAW = PCW + (short)(EAW-1);                             \
  130.         m6502_ICount -= (PCH == EAH) ? 4 : 5;                    \
  131.         PCD = EAD;                                                \
  132.         CHANGE_PC;                                                \
  133.     }                                                            \
  134.     else                                                        \
  135.     {                                                            \
  136.         PCW += 2;                                                \
  137.         m6502_ICount -= 2;                                        \
  138.     }
  139.  
  140. /* 65ce02 ******************************************************
  141.  *    cle clear disable extended stack flag
  142.  ***************************************************************/
  143. #define CLE                                                     \
  144.         P|=F_E
  145.  
  146. /* 65ce02 ******************************************************
  147.  *    see set disable extended stack flag
  148.  ***************************************************************/
  149. #define SEE                                                     \
  150.         P&=~F_E
  151.  
  152. /* 65ce02 ******************************************************
  153.  *    map
  154.  ***************************************************************/
  155. #define MAP                                                     \
  156.  logerror("m65ce02 at pc:%.4x unknown op map a:%.2x x:%.2x y:%.2x z:%.2x\n", \
  157.   m65ce02.pc.w.l-1, m65ce02.a, m65ce02.x, m65ce02.y, m65ce02.z);
  158.  
  159. /* 65ce02 ******************************************************
  160.  *    rts imm
  161.  ***************************************************************/
  162. /* who knows 
  163.    freeing local variables of procedure
  164.    or freeing parameters of procedure call (more likely) */
  165. #define RTS_IMM                                                 \
  166.  logerror("m65ce02 at pc:%.4x unknown op rts %.2x\n",m65ce02.pc.w.l-2,tmp);
  167.  
  168. /* 65ce02 ******************************************************
  169.  *    NEG accu
  170.  *    [7] -> [7][6][5][4][3][2][1][0] -> C
  171.  ***************************************************************/
  172. /* not sure about this */
  173. #if 1
  174. #define NEG                                                     \
  175.  logerror("m65ce02 at pc:%.4x not sure neg\n",m65ce02.pc.w.l-1);\
  176.     A= (A^0xff)+1;                                                \
  177.     SET_NZ(A)
  178. #else
  179. #define NEG                                                     \
  180.     tmp = A; A=0; SBC;
  181. #endif
  182.  
  183. /* 65ce02 ******************************************************
  184.  *    ASR arithmetic (signed) shift right
  185.  *    [7] -> [7][6][5][4][3][2][1][0] -> C
  186.  ***************************************************************/
  187. #define ASR_65CE02                                                \
  188.     P = (P & ~F_C) | (tmp & F_C);                                \
  189.     tmp = (signed char)tmp >> 1;                                \
  190.     SET_NZ(tmp)
  191.  
  192. /* 65ce02 ******************************************************
  193.  *    ASW arithmetic shift left word
  194.  *    [c] <- [15]..[6][5][4][3][2][1][0]
  195.  ***************************************************************/
  196. /* not sure about how 16 bit memory modifying is executed */
  197. #define ASW                                                     \
  198.     tmp.w.l = tmp.w.l << 1;                                     \
  199.     P = (P & ~F_C) | (tmp.b.h2 & F_C);                            \
  200.     SET_NZ_WORD(tmp);                                            
  201.  
  202. /* 65ce02 ******************************************************
  203.  *    ROW rotate left word
  204.  *    [c] <- [15]..[6][5][4][3][2][1][0] <- C
  205.  ***************************************************************/
  206. /* not sure about how 16 bit memory modifying is executed */
  207. #define ROW                                                     \
  208.     tmp.d =(tmp.d << 1);                                        \
  209.     tmp.w.l |= (P & F_C);                                        \
  210.     P = (P & ~F_C) | (tmp.w.l & F_C);                            \
  211.     SET_NZ_WORD(tmp);                                            \
  212.  
  213. /* 65ce02 ******************************************************
  214.  *    CPZ Compare index Z
  215.  ***************************************************************/
  216. #define CPZ                                                     \
  217.     P &= ~F_C;                                                    \
  218.     if (Z >= tmp)                                                \
  219.         P |= F_C;                                                \
  220.     SET_NZ((UINT8)(Z - tmp))
  221.  
  222. /* 65ce02 ******************************************************
  223.  *    DEZ Decrement index Z
  224.  ***************************************************************/
  225. #define DEZ                                                     \
  226.     Z = (UINT8)--Z;                                             \
  227.     SET_NZ(Z)
  228.  
  229. /* 65ce02 ******************************************************
  230.  *    DEC Decrement memory word
  231.  ***************************************************************/
  232. /* not sure about this */
  233. #define DEW                                                     \
  234.     tmp.w.l = --tmp.w.l;                                        \
  235.     SET_NZ_WORD(tmp)
  236.  
  237. /* 65ce02 ******************************************************
  238.  *    DEZ Decrement index Z
  239.  ***************************************************************/
  240. #define INZ                                                     \
  241.     Z = (UINT8)++Z;                                             \
  242.     SET_NZ(Z)
  243.  
  244. /* 65ce02 ******************************************************
  245.  *    INW Increment memory word
  246.  ***************************************************************/
  247. #define INW                                                     \
  248.     tmp.w.l = ++tmp.w.l;                                        \
  249.     SET_NZ_WORD(tmp)
  250.  
  251. /* 65ce02 ******************************************************
  252.  *    LDZ Load index Z
  253.  ***************************************************************/
  254. #define LDZ                                                     \
  255.     Z = (UINT8)tmp;                                             \
  256.     SET_NZ(Z)
  257.  
  258. /* 65ce02 ******************************************************
  259.  * STZ    Store index Z
  260.  ***************************************************************/
  261. #define STZ_65CE02                                                \
  262.     tmp = Z
  263.  
  264. /* 65ce02 ******************************************************
  265.  *    PHZ Push index z
  266.  ***************************************************************/
  267. #define PHZ                                                     \
  268.     PUSH(Z)
  269.  
  270. /* 65ce02 ******************************************************
  271.  *    PLA Pull accumulator
  272.  ***************************************************************/
  273. #define PLZ                                                     \
  274.     PULL(Z); \
  275.     SET_NZ(Z)
  276.  
  277. /* 65ce02 ******************************************************
  278.  * TAZ    Transfer accumulator to index z
  279.  ***************************************************************/
  280. #define TAZ                                                     \
  281.     Z = A;                                                        \
  282.     SET_NZ(Z)
  283.  
  284. /* 65ce02 ******************************************************
  285.  * TZA    Transfer index z to accumulator
  286.  ***************************************************************/
  287. #define TZA                                                     \
  288.     A = Z;                                                        \
  289.     SET_NZ(A)
  290.  
  291. /* 65ce02 ******************************************************
  292.  * TSY    Transfer stack pointer to index y
  293.  ***************************************************************/
  294. #define TSY                                                     \
  295.     Y = SPH;                                                    \
  296.     SET_NZ(Y)
  297.  
  298. /* 65ce02 ******************************************************
  299.  * TYS    Transfer index y to stack pointer
  300.  ***************************************************************/
  301. #define TYS                                                     \
  302.     SPH = Y;
  303.  
  304. /* 65ce02 ******************************************************
  305.  * TAB    Transfer accumulator to Direct Page
  306.  ***************************************************************/
  307. #define TAB                                                     \
  308.     B = A;                                                        \
  309.     SET_NZ(B)
  310.  
  311. /* 65ce02 ******************************************************
  312.  * TBA    Transfer direct page to accumulator
  313.  ***************************************************************/
  314. #define TBA                                                     \
  315.     A = B;                                                        \
  316.     SET_NZ(A)
  317.  
  318. /* 65ce02 ******************************************************
  319.  *    BCC Branch if carry clear
  320.  ***************************************************************/
  321. #define BCC_WORD BRA_WORD(!(P & F_C))
  322.  
  323. /* 65ce02 ******************************************************
  324.  *    BCS Branch if carry set
  325.  ***************************************************************/
  326. #define BCS_WORD BRA_WORD(P & F_C)
  327.  
  328. /* 65ce02 ******************************************************
  329.  *    BEQ Branch if equal
  330.  ***************************************************************/
  331. #define BEQ_WORD BRA_WORD(P & F_Z)
  332.  
  333. /* 65ce02 ******************************************************
  334.  *    BMI Branch if minus
  335.  ***************************************************************/
  336. #define BMI_WORD BRA_WORD(P & F_N)
  337.  
  338. /* 65ce02 ******************************************************
  339.  *    BNE Branch if not equal
  340.  ***************************************************************/
  341. #define BNE_WORD BRA_WORD(!(P & F_Z))
  342.  
  343. /* 65ce02 ******************************************************
  344.  *    BPL Branch if plus
  345.  ***************************************************************/
  346. #define BPL_WORD BRA_WORD(!(P & F_N))
  347.  
  348. /* 65ce02 ******************************************************
  349.  * BVC    Branch if overflow clear
  350.  ***************************************************************/
  351. #define BVC_WORD BRA_WORD(!(P & F_V))
  352.  
  353. /* 65ce02 ******************************************************
  354.  * BVS    Branch if overflow set
  355.  ***************************************************************/
  356. #define BVS_WORD BRA_WORD(P & F_V)
  357.  
  358. /* 65ce02 ******************************************************
  359.  *    JSR Jump to subroutine
  360.  *    decrement PC (sic!) push PC hi, push PC lo and set
  361.  *    PC to the effective address
  362.  ***************************************************************/
  363. #define JSR_IND                                                 \
  364.     EAL = RDOPARG();                                            \
  365.     PUSH(PCH);                                                    \
  366.     PUSH(PCL);                                                    \
  367.     EAH = RDOPARG();                                            \
  368.     PCL = RDMEM(EAD);                                            \
  369.     EAL++;    /* booby trap: stay in same page! ;-) */            \
  370.     PCH = RDMEM(EAD);                                            \
  371.     CHANGE_PC
  372.  
  373. /* 65ce02 ******************************************************
  374.  *    JSR Jump to subroutine
  375.  *    decrement PC (sic!) push PC hi, push PC lo and set
  376.  *    PC to the effective address
  377.  ***************************************************************/
  378. #define JSR_INDX                                                \
  379.     EAL = RDOPARG()+X;                                            \
  380.     PUSH(PCH);                                                    \
  381.     PUSH(PCL);                                                    \
  382.     EAH = RDOPARG();                                            \
  383.     PCL = RDMEM(EAD);                                            \
  384.     EAL++;    /* booby trap: stay in same page! ;-) */            \
  385.     PCH = RDMEM(EAD);                                            \
  386.     CHANGE_PC
  387.  
  388. /* 65ce02 ******************************************************
  389.  *    PLP Pull processor status (flags)
  390.  ***************************************************************/
  391. #undef PLP
  392. #define PLP                                                     \
  393.     if ( P & F_I )                                                \
  394.     {                                                            \
  395.         PULL(P);                                                \
  396.         if( m6502.irq_state != CLEAR_LINE && !(P & F_I) )        \
  397.         {                                                        \
  398.             LOG(("M65ce02#%d PLP sets after_cli\n",             \
  399.                 cpu_getactivecpu()));                            \
  400.             m6502.after_cli = 1;                                \
  401.         }                                                        \
  402.     }                                                            \
  403.     else                                                        \
  404.     {                                                            \
  405.         PULL(P);                                                \
  406.     }                                                            \
  407.     P |= F_B
  408.  
  409. /* 65ce02 ********************************************************
  410.  * RTI    Return from interrupt
  411.  * pull flags, pull PC lo, pull PC hi and increment PC
  412.  *    PCW++;
  413.  ***************************************************************/
  414. #undef RTI
  415. #define RTI                                                     \
  416.     PULL(P);                                                    \
  417.     PULL(PCL);                                                    \
  418.     PULL(PCH);                                                    \
  419.     P |= F_B;                                                    \
  420.     if( m65ce02.irq_state != CLEAR_LINE && !(P & F_I) )         \
  421.     {                                                            \
  422.         LOG(("M65ce02#%d RTI sets after_cli\n",                 \
  423.             cpu_getactivecpu()));                                \
  424.         m6502.after_cli = 1;                                    \
  425.     }                                                            \
  426.     CHANGE_PC
  427.  
  428. /* 65ce02 ********************************************************
  429.  * TXS    Transfer index X to stack LSB
  430.  * no flags changed (sic!)
  431.  * txs tys not interruptable
  432.  ***************************************************************/
  433. #undef TXS
  434. #define TXS                                                     \
  435.         S = X;                                                    \
  436.         if (PEEK_OP() == 0x2b /*TYS*/ )                         \
  437.         {                                                        \
  438.                 UINT8 op = RDOP();                                \
  439.                 (*m65ce02.insn[op])();                            \
  440.         }
  441.